package com.andf.common;

import static org.apache.ibatis.jdbc.SqlBuilder.*;
/**
 * @author lilubing
 * @Description: TODO(这里用一句话描述这个方法的作用)
 * @throws
 * @date 2013-4-24 下午04:42:21
 */
public class CUDTemplate<T extends MyBatisPojo> {
	public String insert(T obj) {
		BEGIN();
		
		INSERT_INTO(obj.tablename());
		obj.caculationColumnList();
		VALUES(obj.returnInsertColumnsName(), obj.returnInsertColumnsDefine());

		return SQL();
	}
	
	public String update(T obj) {
		String idname = obj.id();
		
		BEGIN();
		
		UPDATE(obj.tablename());
		obj.caculationColumnList();
		SET(obj.returnUpdateSet());
		WHERE(idname + "=#{" + idname + "}");
		
		return SQL();
	}
	
	public String delete(T obj) {
		String idname = obj.id();
		
		BEGIN();
		
		DELETE_FROM(obj.tablename());
		WHERE(idname + "=#{" + idname + "}");
		
		return SQL();
	}
}
